package yagl.action;

import java.util.HashMap;
import java.util.Map;

import sjgl.agent.IsjAgent;
import yagl.agent.CKFAAgent;
import common.Const;
import common.MyUtils;
import common.BaseClasses.CommonAction;
import common.BaseClasses.util.IocUtil;

public class CKFAAction extends CommonAction{

	private CKFAAgent ckfaAgent;
	
    private IsjAgent sjAgentImpl;

	private  Map<Object, Object> resultMap;
	private  Map<Object, Object> ckfaResultMap;
	
	 public CKFAAction(){
	    	try {
				this.ckfaAgent=(CKFAAgent) IocUtil.getIocImpl("yagl/ioc/ioc-yjzy.xml","ckfaAgent");
				this.sjAgentImpl=(IsjAgent) IocUtil.getIocImpl("sjgl/ioc/ioc-sj.xml","sjAgentImpl");

	    	} catch (Throwable e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	    }
	 
	 /**
	  * 跳转到参考方案页面
	  * @return
	  */
	 public String toCkfaPage(){
	    	Map map=new HashMap();
	    	resultMap=sjAgentImpl.findSjByPage(1,6,map);
	    	setPageParam(resultMap);
	    	return "toCkfaPage";
	    }
	 /**
	     * 点击分页条下的数字触发的分页action
	     * @return
	     */
	 public String findEveByPage(){
	    	paramMap.put("startTime",getParameter("startTime",""));
	    	paramMap.put("endTime", getParameter("endTime",""));
	    	paramMap.put("eventName", getParameter("eventName",""));
	    	Map map=new HashMap();
	    	map.put("startTime", getParameter("startTime", ""));
	    	map.put("endTime", getParameter("endTime", ""));
	    	map.put("eventName", getParameter("eventName",""));
	    	resultMap=sjAgentImpl.findSjByPage(pageBean.getCurrentPage(), pageBean.getPageSize(), map);
	    	System.out.println("分页得到的结果"+resultMap);
	    	
	        setPageParam(resultMap);
	    	return "toCkfaFenYePage";
//	    	return "toCkfaFenYePage";
	 }
	 
	 /**
	     * 根据日期查询，或者事件名称查询事件
	     */
	    public String searchSj(){
	    	Map map=new HashMap();
	    	map.put("startTime", getParameter("startTime"));
	    	map.put("endTime",getParameter("endTime"));
	    	map.put("eventName", getParameter("eventName"));
	    	//将查询条件存入到分页标签里面
	    	paramMap.put("startTime", getParameter("startTime"));
	    	paramMap.put("endTime", getParameter("endTime"));
	    	paramMap.put("eventName", getParameter("eventName"));
	    	resultMap=sjAgentImpl.findSjByPage(1, 6, map);
	    	System.out.println("-------------"+resultMap);
	        setPageParam(resultMap);
	    	return "toCkfaFenYePage";
	    }
	    /**
	     * 根据是否有参考方案id添加或修改
	     * @return
	     */
	    public String saveOrUpdataCkfa(){
	    	String ckfaId=getParameter("ckfaId");
	    	Map map=new HashMap();
	    	String a=getParameter("evenId");
	    	if(ckfaId!=null&&!(ckfaId.equals(""))){
	    		map.put("id", ckfaId);
	    		map.put("eve_cd", getParameter("evenId"));
	    		map.put("refplan_nm", getParameter("refplan_nm"));
	    		map.put("xgyg", getParameter("xgyg"));
	    		map.put("clfs", getParameter("clfs"));
	    		ckfaAgent.updataCk(map);
	    		return null;
	    	}
	    	else{
	    		map.put("id", MyUtils.getUUID());
	    		map.put("eve_cd", getParameter("evenId"));
	    		map.put("refplan_nm", getParameter("refplan_nm"));
	    		map.put("xgyg", getParameter("xgyg"));
	    		map.put("clfs", getParameter("clfs"));
	    		System.out.println("---------map:"+map);
	    		ckfaAgent.insert(map);
	    		return "success";
	    	}
	    	
	    }
		/**
		 * 根据事件id查询参考方案列表
		 * @return
		 */
	    public String selectCkfaByEve(){
	    	String even_id=getParameter("evenId");
			Map map=new HashMap();
			map.put("eve_id", even_id);
			paramMap.put("eve_id", getParameter("even_id"));
			ckfaResultMap=ckfaAgent.selectCkfaById(map);
			return "toCkfaSubListPage";
		}
	    
	    /**
	     * 批量删除参考方案
	     */
	    public void DeleteTm(){
	    	String ckfaIdArr=getParameter("ckfaIdArr");
	    	System.out.println(getParameter("ckfaIdArr"));
	    	String result=ckfaAgent.deleteCk(ckfaIdArr);
	    	System.out.println(result);
	    	writeStringToResponse(result);
	    }
	    /**
	     * 事件下的参考方案列表分页读取
	     * @return
	     */
//	    public String selectCkByIdPage(){
//	    	paramMap.put("eve_id",getParameter("eve_id",""));
//	    	Map map=new HashMap();
//			map.put("eve_id", getParameter("eve_id",""));
//			ckfaResultMap=ckfaAgent.selectCkfaById(map);
//			setPageParam(ckfaResultMap);
//			return "toCkfaSubListPage";
//	    }
	public CKFAAgent getCkfaAgent() {
		return ckfaAgent;
	}


	public void setCkfaAgent(CKFAAgent ckfaAgent) {
		this.ckfaAgent = ckfaAgent;
	}


	public IsjAgent getSjAgentImpl() {
		return sjAgentImpl;
	}


	public void setSjAgentImpl(IsjAgent sjAgentImpl) {
		this.sjAgentImpl = sjAgentImpl;
	}


	public Map<Object, Object> getResultMap() {
		return resultMap;
	}


	public void setResultMap(Map<Object, Object> resultMap) {
		this.resultMap = resultMap;
	}

	public Map<Object, Object> getCkfaResultMap() {
		return ckfaResultMap;
	}

	public void setCkfaResultMap(Map<Object, Object> ckfaResultMap) {
		this.ckfaResultMap = ckfaResultMap;
	}
	 
}
